package com.grm.workflow.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.grm.common.entity.Result;
import com.grm.sys.model.SysPost;
import com.grm.workflow.model.WfForm;
import com.grm.workflow.request.WfFormQueryParam;
import com.grm.workflow.service.WfFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/workflow/form")
public class WfFormController {
    @Autowired
    private WfFormService wfFormService;

    @GetMapping("query/all")
    public Result queryAll() {
        List<WfForm> wfFormList = wfFormService.queryAll();
        return Result.success(wfFormList);
    }

    @PostMapping("/list")
    public Result querySelective(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestBody WfFormQueryParam queryParam) {
        // 开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<WfForm> wfFormList = wfFormService.querySelective(queryParam);
        PageInfo<WfForm> pageInfo = new PageInfo<>(wfFormList);
        return Result.success(pageInfo.getList(), pageInfo.getTotal());
    }

    @GetMapping("query/{id}")
    public Result queryById(@PathVariable Long id) {
        WfForm wfForm = wfFormService.queryById(id);
        return Result.success(wfForm);
    }
}
